package com.huilink.webmail.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.ServiceDefTarget;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.huilink.webmail.dtolayer.WebMailAppService;
import com.huilink.webmail.dtolayer.WebMailAppServiceAsync;
import com.huilink.webmail.util.client.ListenerManager;
import com.huilink.webmail.util.client.ListenerManagerImpl;
import com.huilink.webmail.util.client.WidgetManager;
import com.huilink.webmail.util.client.WidgetManagerImpl;

public class WebMailApp implements EntryPoint {

	
	private ListenerManager listenerManager;

	private WidgetManager widgetManager;

	private MailServiceWidget mailServicePage;
	
	private String styleLoginTop="default-login-top";
	
	private String styleLoginBack="default-login-back";
	
	private String styleLoginWhole="default-login-whole";
	
	private WebMailAppServiceAsync service;
	
	private HorizontalPanel topPanel=new HorizontalPanel();
	
	private HorizontalPanel loginPanel=new HorizontalPanel();
	
	private HorizontalPanel maskPanel = new HorizontalPanel();
	
	private HorizontalPanel bottomPanel=new HorizontalPanel();
	

	public WebMailApp() {
		service = (WebMailAppServiceAsync) GWT
		.create(WebMailAppService.class);
		ServiceDefTarget endpoint = (ServiceDefTarget) service;
		String moduleRelativeURL = GWT.getModuleBaseURL() + "/webmail";
		endpoint.setServiceEntryPoint(moduleRelativeURL);
		widgetManager = new WidgetManagerImpl();
		listenerManager =  new ListenerManagerImpl();
	}
	
	public void onModuleLoad() {
		VerticalPanel panel = new VerticalPanel();
		panel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
		
		topPanel.setHeight("209px");//241
		topPanel.setWidth("861px");
		topPanel.setStyleName(styleLoginTop);
		
		topPanel.add(new Label(""));
		
		HorizontalPanel welcomePanel = new HorizontalPanel();
		welcomePanel.setWidth("861px");
		welcomePanel.setStyleName(styleLoginBack);
		welcomePanel.add(new Label(""));
		MailServiceWidget main = new MailServiceWidget(service, listenerManager, widgetManager);
		maskPanel.add(main);
	
		
		Image backGroudBottom =  new Image();
		backGroudBottom.setUrl("login-page-bottom.gif");
		bottomPanel.add(backGroudBottom);
		bottomPanel.setHeight("92px");
		Button help = new Button("Help");
		bottomPanel.setCellHorizontalAlignment(help,
				HasHorizontalAlignment.ALIGN_RIGHT);
		
		panel.add(topPanel);
		panel.add(welcomePanel);
		panel.add(maskPanel);
		panel.add(bottomPanel);
		
		panel.setStyleName(styleLoginWhole);
		RootPanel.get().add(panel);
		

		

	}

	
	public void setListenerManager(ListenerManager listenerManager) {
		this.listenerManager = listenerManager;
	}

	public void setWidgetManager(WidgetManager widgetManager) {
		this.widgetManager = widgetManager;
	}
	
	public void setService(WebMailAppServiceAsync service) {
		this.service = service;
	}
}
